import request from '@/utils/request'

/**
 * 获取订单信息
 */
export const findCheckOutInfo = () => {
  return request('/member/order/pre', 'get')
}

/**
 * 添加收货地址
 * @param {Object} address 收货地址信息
 * @returns Promise
 */
export const addAddress = (address) => {
  return request('/member/address', 'POST', address)
}

/**
 * 修改收货地址
 * @param {Object} address 收货地址信息
 * @param {String} id 收货地址id
 * @returns Promise
 */
export const addAddressEdit = (address) => {
  return request(`/member/address/${address.id}`, 'POST', address)
}

/**
 * 提交订单
 * @param {Object} order
 * @returns Promise
 */
export const createdOrder = (order) => {
  return request('/member/order', 'POST', order)
}

// /**
//  * 生成订单(即填写订单或结算页)
//  * @param {String} cancelReason 取消理由
//  * @returns Promise
//  */
// export const createOrder = (cancelReason) => {
//   return request('/member/order/pre', 'GET', cancelReason)
// }

/**
 * 获取订单详情
 * @param {String} id 订单id
 * @returns Promise
 */
export const findOrderDetail = (id) => {
  return request(`/member/order/${id}`, 'GET')
}

/**
 * 获取个人中心订单详情
 * @param {object} { page：页码, pageSize：页尺寸, orderState：订单状态 }
 * @returns Promise
 */
export const findOrderList = ({ page, pageSize, orderState }) => {
  return request('/member/order', 'GET', { page, pageSize, orderState })
}

/**
 * 取消订单
 * @param {String} id 订单id
 * @returns Promise
 */
export const cancelOrder = ({ orderId, cancelReason }) => {
  return request(`/member/order/${orderId}/cancel`, 'PUT', { cancelReason })
}

/**
 * 再次购买
 * @param {String} id 订单id
 * @returns Promise
 */
export const repurchaseOrder = ({ id }) => {
  return request(`/member/order/repurchase/${id}`, 'GET')
}

/**
 * 删除订单
 * @param {String} id 订单id
 * @returns Promise
 */
export const deleteOrder = ({ id }) => {
  return request('/member/order', 'DELETE', { ids: [id] })
}

/**
 * 确认收货
 * @param {String} id 订单id
 * @returns Promise
 */
export const confirmOrder = ({ id }) => {
  return request(`/member/order/${id}/receipt`, 'PUT')
}

/**
 * 查看物流
 * @param {String} id 订单id
 * @returns Promise
 */
export const logisticsOrder = ({ id }) => {
  return request(`/member/order/${id}/logistics`, 'GET')
}
